<?php
namespace App\Servers\Backend;

use App\Repositories\Backend\ButtomRepository;
use App\Repositories\Backend\CopywriterRepository;


class BrandServer extends CommonServer
{

    public function __construct(
        ButtomRepository $buttomRepository,
        CopywriterRepository $copywriterRepository

    ) {
        $this->buttomRepository  = $buttomRepository;
        $this->copywriterRepository  = $copywriterRepository;
    }

    public function index($input)
    {
        $result['copy']   = $this->copywriterRepository->getLists($input);
        $result['bottom'] = $this->buttomRepository->getLists($input);

        return ['获取成功', $result];
    }


    /**
     * 新增
     * @param  Array $input [bottom_QR_code, bottom_address, bottom_tel, bottom_time, introduce , values]
     * @return Array
     */
    public function create($input)
    {
        $bottom_QR_code  = isset($input['bottom_QR_code']) ? strval($input['bottom_QR_code']) : '';
        $bottom_address  = isset($input['bottom_address']) ? strval($input['bottom_address']) : '';
        $bottom_tel      = isset($input['bottom_tel']) ? strval($input['bottom_tel']) : 0;
        $bottom_time     = isset($input['bottom_time']) ? strval($input['bottom_time']) : 0;
        $introduce       = isset($input['introduce']) ? strval($input['introduce']) : '';
        $values          = isset($input['values']) ? strval($input['values']) : '';


        if (!$bottom_QR_code || !$bottom_address || !$bottom_tel || !$bottom_time || !$introduce || !$values) {
            return ['code' => ['x00004', 'system']];
        }

        $result['list'] = $this->buttomRepository->create($bottom_QR_code, $bottom_address, $bottom_tel, $bottom_time);
        $result['lists'] = $this->copywriterRepository->create($introduce, $values);

        if (!$result['list'] || !$result['lists']) {
            return ['code' => ['x00001', 'system']];
        }

        return ['新增成功', $result];
    }

}
